package com.glhtgyxy.biyesheji.Controller;

import com.glhtgyxy.biyesheji.Pojo.user;
import com.glhtgyxy.biyesheji.Service.userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@Controller
@RequestMapping("user")
@CrossOrigin(origins = "*")
public class userController {

    @Autowired
    private userService userservice;

    @RequestMapping("findalluser")
    @ResponseBody
    public ArrayList<user> selectAllUser(){
        System.out.println("开始查询用户数据");
        ArrayList<user> users = userservice.selectAllUser();
        System.out.println("查询成功，返回："+users);
        return users;
    }
    @RequestMapping("deleteuser/{id}")
    @ResponseBody
    public Boolean deleteUser(@PathVariable int id){
        System.out.println("开始删除用户数据");
        boolean bool=true;
        bool = userservice.deleteUser(id);
        System.out.println("删除+"+id);
        System.out.println("执行成功，返回："+bool);
        return bool;
    }
    @RequestMapping("updateuser/{id}/{username}/{useraccount}/{userpassword}")
    @ResponseBody
    public Boolean updateuser(@PathVariable int id,
                              @PathVariable String username,
                              @PathVariable String useraccount,
                              @PathVariable String userpassword){
        System.out.println("开始修改用户数据");
        boolean bool=true;
        bool = userservice.updateUser(id,username,useraccount,userpassword);
        System.out.println("执行成功，返回："+bool);
        return bool;
    }
    @RequestMapping("adduser/{username}/{useraccount}/{userpassword}")
    @ResponseBody
    public Boolean adduser(@PathVariable String username,
                           @PathVariable String useraccount,
                           @PathVariable String userpassword){
        System.out.println("开始新增用户");
        boolean bool=true;
        bool = userservice.addUser(username,useraccount,userpassword);
        System.out.println("执行成功，返回："+bool);
        return bool;
    }
    @RequestMapping("finduser/{serchtext}")
    @ResponseBody
    public ArrayList<user> finduser(@PathVariable String serchtext){
        System.out.println("开始模糊查找用户"+serchtext);
        ArrayList<user> users = userservice.findUser(serchtext);
        System.out.println("执行成功，返回："+ users);
        return users;
    }

}
